<!-- eslint-disable vue/multi-word-component-names -->
<template>
    <div class="qilin-pRank">
        <div class="qilin-pRank-tab">
            <el-tabs v-model="activeName">
                <el-tab-pane label="P职级晋升调整总表" name="promotion"></el-tab-pane>
                <el-tab-pane label="绩效积分" name="achievements"></el-tab-pane>
                <el-tab-pane label="资质积分" name="qualifications"></el-tab-pane>
                <el-tab-pane label="创新积分" name="innovate"></el-tab-pane>
                <el-tab-pane label="贡献积分" name="contribution"></el-tab-pane>
            </el-tabs>
            <el-form inline size="mini" :model="formSearch" label-position="right"
                v-if="$store.getters.userInfo.isManager == 1" class="qilin-search-form">
                <el-form-item label="员工编码:" prop="employeeCode">
                    <el-input type="text" placeholder="请输入   " v-model="formSearch.employeeCode" clearable></el-input>
                </el-form-item>
                <el-form-item label="姓名:" prop="employeeName">
                    <el-input type="text" placeholder="请输入" v-model="formSearch.employeeName" clearable></el-input>
                </el-form-item>
                <el-form-item label="部门:" prop="employeeDepartment">
                    <el-select placeholder="请选择" v-model="formSearch.employeeDepartment" clearable>
                        <el-option v-for="item in employeeDepartmentList" :key="item.id" :label="item.label"
                            :value="item.value"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="时间:" prop="date" v-if="['promotion','achievements'].includes(activeName)">
                    <el-date-picker v-model="formSearch.date" type="daterange" range-separator="至"
                        start-placeholde="开始时间" end-placeholde="结束时间" format="yyyy" value-format="yyyy"
                        :picker-options="pickerOptions"></el-date-picker>
                </el-form-item>
                <el-form-item label="证书名称:" prop="certificateName" v-else-if="activeName === 'qualifications' ">
                    <el-input type="text" placeholder="请输入" v-model="formSearch.certificateName" clearable></el-input>
                </el-form-item>
                <el-form-item label="成果名称:" prop="achievementName" v-else-if="activeName === 'innovate' ">
                    <el-input type="text" placeholder="请输入" v-model="formSearch.achievementName" clearable></el-input>
                </el-form-item>
                <el-form-item label="工龄" prop="workingYears" v-else>
                    <el-select placeholder="请选择" v-model="formSearch.workingYears">
                        <el-option v-for="item in workingYearList" :key="item.value" :label="item.label"
                            :value="item.value" clearable></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item class="search-btn">
                    <el-button type="primary" size="mini" @click="searchButton()">查询</el-button>
                    <el-button type="default" size="mini" @click="resetButton()">重置</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="qilin-pRank-table">
            <div class="qilin-pRank-table-btn">
                <el-button v-if="$store.getters.userInfo.isManager == 1" size="mini" plain icon="el-icon-download"
                    @click="importButton()">导入</el-button>
                <el-button size="mini" plain icon="el-icon-upload2" @click="exportButton()">导出</el-button>
                <el-button v-if="$store.getters.userInfo.isManager == 1" size="mini" plain icon="el-icon-bottom"
                    @click="downloadButton()">下载模板</el-button>
                <el-button size="mini" plain icon="el-icon-printer" v-print="printObj">打印</el-button>
                <el-button size="mini" plain icon="el-icon-document-add"
                    v-if="['qualifications','contribution','innovate'].includes(this.activeName) && $store.getters.userInfo.isManager == 1"
                    @click="insertButton()">新增</el-button>
                <el-upload action="#" ref="upload" accept=".xlsx,.xls" :limit="1" :auto-upload="false"
                    :on-change="changeXlsx" :http-request="requestXlsx"></el-upload>
            </div>
            <el-table :data="tableConfig.data" stripe @select="selectData" @select-all="selectAllData" id="table">
                <!-- <el-table-column type="selection" width="50" align="center"></el-table-column> -->
                <el-table-column label="编号" width="50" align="center">
                    <template v-slot:default="scope">
                        <!-- <template #default="scope"> -->
                        <!-- <template v-slot="scope"> -->
                        <!-- <template slot-scope="scope"> -->
                        <span>{{scope.$index+1}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="员工编码" prop="employeeCode" align="center"></el-table-column>
                <el-table-column label="姓名" prop="employeeName" align="center"></el-table-column>
                <el-table-column label="部门" prop="employeeDepartment" align="center"></el-table-column>
                <template v-for="item in tableConfig.tableColumn">
                    <el-table-column :label="item.year+'年'" :key="item.year" align="center"
                        v-if="activeName === 'promotion'">
                        <template v-for="ite in item.data">
                            <el-table-column :label="ite.label" :key="ite.label" :prop="ite.prop" align="center"
                                :width="ite.width">
                                <template v-slot:default="scope">
                                    <span v-if="ite.prop.includes('rankAdjust')">
                                        {{scope.row[ite.prop] ? "是" : "否"}}
                                    </span>
                                    <span v-else>{{scope.row[ite.prop] ?? "-"}}</span>
                                </template>
                            </el-table-column>
                        </template>
                    </el-table-column>
                    <el-table-column :key="item.label" :label="item.label" :prop="item.prop" align="center" v-else
                        :show-overflow-tooltip="item.prop === 'remark'">
                        <template v-slot:default="scope">
                            <span>{{scope.row[item.prop] ?? "-"}}</span>
                        </template>
                    </el-table-column>
                </template>
                <el-table-column label="操作" fixed="right" width="100" align="center"
                    v-if="['qualifications'].includes(this.activeName)">
                    <template v-slot:default="scope">
                        <el-button type="text" @click="viewButtton(scope)">查看</el-button>
                        <el-button type="text" @click="updateButton(scope)"
                            v-if="$store.getters.userInfo.isManager == 1">编辑</el-button>
                    </template>
                </el-table-column>
                <el-table-column label="操作" fixed="right" width="100" align="center"
                    v-if="['innovate'].includes(this.activeName)">
                    <template v-slot:default="scope">
                        <el-button type="text" @click="updateButton(scope)"
                            v-if="$store.getters.userInfo.isManager == 1">编辑</el-button>
                    </template>
                </el-table-column>
                <el-table-column label="操作" fixed="right" width="100" align="center"
                    v-if="['promotion'].includes(this.activeName)">
                    <template v-slot:default="scope">
                        <el-button type="text" @click="updateButton(scope)"
                            v-if="$store.getters.userInfo.isManager == 1" :disabled="updateable">编辑</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination :current-page="paginationsObj.currentPage" :page-sizes="paginationsObj.pageSizes"
                :page-size="paginationsObj.pageSize" :total="paginationsObj.total" :layout="paginationsObj.layout"
                background @current-change="handleCurrentPage" @size-change="handleSizeChange"></el-pagination>
        </div>
        <PromotionDialog ref="PromotionDialog" @refresh="getTableData"></PromotionDialog>
        <QualificationDialog ref="QualificationDialog" @refresh="getTableData"></QualificationDialog>
        <ViewQualification ref="ViewQualification"></ViewQualification>
        <ContributionDialog ref="ContributionDialog" @refresh="getTableData"></ContributionDialog>
        <InnovateDialog ref="InnovateDialog" @refresh="getTableData"></InnovateDialog>
    </div>
</template>
<script>
import {
    getPromotionData,
    getQualificationsData,
    getAchievementsData,
    getInnovateData,
    getContributionData,
    importExcelData,
    exportExcelPromotionData,
    exportExcelAchievementsData,
    exportExcelQualificationsData,
    exportExcelInnovateData,
    exportExcelContributionData
} from "@/api/index.js";

import QualificationDialog from "./components/qualificationDialog.vue";
import ViewQualification from "./components/viewQualification.vue";
import PromotionDialog from "./components/promotionDialog.vue";
import ContributionDialog from "./components/contributionDialog.vue";
import InnovateDialog from "./components/InnovateDialog.vue";
export default {
    inject: ["uploadImageUrl", "uploadXlsxUrl"],
    components: {
        QualificationDialog,
        ViewQualification,
        PromotionDialog,
        ContributionDialog,
        InnovateDialog
    },
    data() {
        return {
            activeName: "promotion", //当前tab标签
            formSearch: { //搜索表单配置项
                employeeCode: "", //员工编码
                employeeName: "", //姓名
                employeeDepartment: "", //部门
                date: "", //时间
                certificateName: "", //证书名称
                achievementName: "", //成果名称
                workingYears: "" //工龄
            },
            pickerOptions: { //日期快捷选项配置
                disabledDate(time) {
                    return time.getTime() > Date.now();
                },
                shortcuts: [
                    {
                        text: "本年",
                        onClick(picker) {
                            const year = new Date().getFullYear();
                            picker.$emit("pick", [new Date(year + "-01-01"), new Date()]);
                        }
                    },
                    {
                        text: "去年",
                        onClick(picker) {
                            const year = new Date().getFullYear() - 1;
                            picker.$emit("pick", [new Date(year + "-01-01"), new Date(year + "-12-31")]);
                        }
                    }
                ]
            },
            tableConfig: { //表格配置项
                data: [],
                tableColumn: []
            },
            paginationsObj: { // 表格分页配置项
                currentPage: 1, //当前页
                pageSize: 12, //当前每页数量
                pageSizes: [12, 24, 36], //每页显示多少条选项集
                total: 0, //表格总数量
                layout: "total,prev,pager,next,sizes,jumper"
            },
            printObj: { //打印功能配置项
                id: "table",
                // popTitle:"打印数据",
                extraHead: `
                    <meta http-equiv="Content-Language" content="zh-cn" />,
                    <style>#table {width:100%;} </style>
                `
            },
            workingYearList: [ // 工龄下拉选择数据集
                {
                    label: "1年",
                    value: 1
                },
                {
                    label: "2年",
                    value: 2
                },
                {
                    label: "3年",
                    value: 3
                },
                {
                    label: "4年",
                    value: 4
                },
                {
                    label: "5年",
                    value: 5
                },
                {
                    label: "6年",
                    value: 6
                },
                {
                    label: "7年",
                    value: 7
                },
                {
                    label: "8年",
                    value: 8
                },
                {
                    label: "9年",
                    value: 9
                },
                {
                    label: "10年",
                    value: 10
                },
                {
                    label: "11年",
                    value: 11
                },
                {
                    label: "12年",
                    value: 12
                },
                {
                    label: "13年",
                    value: 13
                },
                {
                    label: "14年",
                    value: 14
                },
                {
                    label: "15年",
                    value: 15
                }
            ],
            employeeDepartmentList: [ // 部门下拉选择数据集
                {
                    label: "综合部",
                    value: "综合部",
                    id: 1
                },
                {
                    label: "财务部",
                    value: "财务部",
                    id: 2
                },
                {
                    label: "市场拓展部",
                    value: "市场拓展部",
                    id: 3
                },
                {
                    label: "系统集成部",
                    value: "系统集成部",
                    id: 4
                },
                {
                    label: "工程部",
                    value: "工程部",
                    id: 5
                },
                {
                    label: "产品研发部",
                    value: "产品研发部",
                    id: 6
                },
                {
                    label: "平台运维部",
                    value: "平台运维部",
                    id: 7
                }
            ],
            currentYear: new Date().getFullYear(), //当前年份
        }
    },
    computed: {
        getData() {
            return function (scope) {
                console.log(scope);
            }
        },
        // 是否可编辑
        updateable() {

            if (this.tableConfig.tableColumn.some((item) => {
                return item.year == this.currentYear;
            })) {

                return false;
            } else {
                return true;
            }
        }
    },
    watch: {
        activeName: {
            handler() {
                this.tableConfig.data = [];
                this.paginationsObj.total = 0;
                this.paginationsObj.currentPage = 1;
                this.paginationsObj.pageSize = 12;
                this.resetButton();
                // this.getTableColumn();
            },
            immediate: true
        }
    },
    methods: {
        // 点击导入按钮事件监听
        importButton() {
            this.$refs['upload'].$children[0].$refs.input.click();
        },
        // 自定义导入事件监听
        requestXlsx(param) {
            console.log(param);
        },
        // 导入文件状态改变事件监听
        changeXlsx(file) {
            // console.log(file,fileList);
            const xlsxType = file.name.split(".").pop();
            if (!["xlsx", "xls"].includes(xlsxType)) {
                this.$message({
                    message: "请上传正确格式的excel文档",
                    type: "warning"
                });
                // this.$refs["upload"].uploadFiles.splice(0,1);
                // this.$refs["upload"].clearFiles();
            } else {
                let formData = new FormData();
                switch (this.activeName) {
                    case "promotion":
                        formData.append("type", 1);
                        break;
                    case "achievements":
                        formData.append("type", 2);
                        break;
                    case "qualifications":
                        formData.append("type", 3);
                        break;
                    case "innovate":
                        formData.append("type", 4);
                        break;
                    case "contribution":
                        formData.append("type", 5);
                        break;
                }
                formData.append("files", file.raw);
                importExcelData(formData).then((res) => {
                    if (res.code === 200) {
                        this.$message({
                            message: "导入成功",
                            type: "success"
                        });
                        this.getTableData();
                        // this.getTableColumn();
                    } else {
                        this.$message({
                            message: res.message || "导入失败",
                            type: "error"
                        });
                        let a = document.createElement("a");
                        a.href = this.uploadImageUrl + res.result.fileUrl;
                        a.download = "错误模板";
                        a.style.display = "none";
                        document.body.appendChild(a);
                        a.dispatchEvent(new MouseEvent("click"));
                        a.remove();
                        if (res.result.successCount && res.result.successCount > 0) {
                            this.getTableData();
                            // this.getTableColumn();
                        }
                    }
                });
            }
            this.$refs["upload"].clearFiles();
        },
        // 点击导出按钮事件监听
        async exportButton() {
            // 处理相关筛选条件
            let params = {};
            Object.keys(this.formSearch).forEach((item) => {
                if (this.formSearch[item]) {
                    params[item] = this.formSearch[item];
                    if (typeof params[item] === "string") {
                        params[item] = params[item].trim();
                    }
                }
            });
            if (params.date && params.date.length > 0) {
                params.startYear = params.date[0];
                params.lastYear = params.date[1];
                Reflect.deleteProperty(params, "date");
            }
            let result, xlsxName;
            let getResult = async (fn, params) => {
                return await fn(params).then((res) => {
                    return res;
                });
            }
            if (this.activeName === "promotion") {
                result = await getResult(exportExcelPromotionData, params);
                xlsxName = "P职级晋升调整总表.xlsx";
            } else if (this.activeName === "achievements") {
                result = await getResult(exportExcelAchievementsData, params);
                xlsxName = "绩效积分.xlsx";
            } else if (this.activeName === "qualifications") {
                result = await getResult(exportExcelQualificationsData, params);
                xlsxName = "资质积分.xlsx";
            } else if (this.activeName === "innovate") {
                result = await getResult(exportExcelInnovateData, params);
                xlsxName = "创新积分.xlsx";
            } else if (this.activeName === "contribution") {
                result = await getResult(exportExcelContributionData, params);
                xlsxName = "贡献积分.xlsx";
            }
            if (result) {
                var blob = new Blob([result], {
                    type: "application/vnd.ms-excel;charset=UTF-8",
                });
                if (window.navigator.msSaveBlob) {//没有此判断的话，ie11下的导出没有效果
                    //    window.navigator.msSaveBlob(blob, unescape(res.headers.filename.replace(/\\u/g, '%u')));
                    window.navigator.msSaveBlob(blob, xlsxName);
                } else {
                    var downloadElement = document.createElement("a");
                    var href = window.URL.createObjectURL(blob); //创建下载的链接
                    downloadElement.href = href;
                    downloadElement.download = xlsxName;
                    document.body.appendChild(downloadElement);
                    downloadElement.click(); //点击下载
                    document.body.removeChild(downloadElement); //下载完成移除元素
                    window.URL.revokeObjectURL(href); //释放掉blob对象
                }
            }
        },
        // 点击下载模板按钮事件监听
        downloadButton() {
            // 方法一
            let a = document.createElement("a");
            switch (this.activeName) {
                case "promotion":
                    a.href = this.uploadXlsxUrl + "P职级晋升调整导入表.xls";
                    a.download = "P职级晋升调整导入表.xls";
                    break;
                case "achievements":
                    a.href = this.uploadXlsxUrl + "绩效积分导入表.xls";
                    a.download = "绩效积分导入表.xls";
                    break;
                case "qualifications":
                    a.href = this.uploadXlsxUrl + "资质积分导入表.xls";
                    a.download = "资质积分导入表.xls";
                    break;
                case "innovate":
                    a.href = this.uploadXlsxUrl + "创新积分导入表.xls";
                    a.download = "创新积分导入表.xls";
                    break;
                case "contribution":
                    a.href = this.uploadXlsxUrl + "贡献积分导入表.xls";
                    a.download = "贡献积分导入表.xls";
                    break;
            }
            a.style.display = "none";
            document.body.appendChild(a);
            a.dispatchEvent(new MouseEvent("click"));
            a.remove();
            // 方法二
            // const iframe=document.createElement("iframe");
            // iframe.src=this.uploadXlsxUrl+"P职级晋升调整导入表.xls";
            // iframe.style.display="none";
            // iframe.style.height=0;
            // document.body.appendChild(iframe);
            // setTimeout(()=>{
            //     document.body.removeChild(iframe);
            // },2000);
        },
        // 清空搜索表单内容事件监听
        // clearFormSearch(){
        //     Object.keys(this.formSearch).forEach((item)=>{
        //         this.formSearch[item]="";
        //     });
        // },
        // 点击查询按钮事件监听
        searchButton() {
            this.getTableColumn();
        },
        // 点击重置按钮事件监听
        resetButton() {
            Object.keys(this.formSearch).forEach((item) => {
                this.formSearch[item] = "";
            });
            this.getTableColumn();
        },
        // 行数据的复选框选择事件监听
        selectData(selection) {
            // console.log(selection,row);
            // 获取相应年份，拆解数据结构
            let startYear, endYear, years;
            if (this.formSearch.date && this.formSearch.date.length > 0) {
                startYear = new Date(this.formSearch.date[0]).getFullYear();
                endYear = new Date(this.formSearch.date[1]).getFullYear();
                years = endYear - startYear;
            } else {
                startYear = endYear = new Date().getFullYear();
                years = endYear - startYear;
            }
            let tempArr = this.$QilinUtils.deepCopy(selection, []);
            if (tempArr && tempArr.length > 0) {
                tempArr.forEach((item) => {
                    item.yearList = [];
                    for (let i = 0; i <= years; i++) {
                        let obj = {};
                        obj.year = startYear + i;
                        Object.keys(item).forEach((ite) => {
                            if (ite.indexOf(startYear + i) != -1) {
                                let key = ite.replace(startYear + i, "");
                                obj[key] = item[ite];
                                // console.log(ite);
                                Reflect.deleteProperty(item, ite);
                            }
                        });
                        item.yearList.push(obj);
                    }
                });
            }
            console.log(tempArr);
        },
        // 表头的全选复选框事件监听
        selectAllData(selection) {
            console.log(selection);
        },
        // 点击新增按钮事件监听
        insertButton() {
            if (this.activeName === "qualifications") {
                this.$refs["QualificationDialog"].initUpdate();
            } else if (this.activeName === "contribution") {
                this.$refs["ContributionDialog"].initUpdate();
            } else if (this.activeName === "innovate") {
                this.$refs["InnovateDialog"].initUpdate();
            }
        },
        // 点击操作-查看按钮事件监听
        viewButtton(scope) {
            this.$refs["ViewQualification"].initView(scope.row);
        },
        // 点击操作-编辑按钮事件监听
        updateButton(scope) {
            if (this.activeName === "qualifications") {
                this.$refs["QualificationDialog"].initUpdate(scope.row);
            } else if (this.activeName === "promotion") {
                this.$refs["PromotionDialog"].initUpdate(scope.row);
            } else if (this.activeName === "innovate") {
                this.$refs["InnovateDialog"].initUpdate(scope.row);
            }
        },
        // 点击切换页码事件监听
        handleCurrentPage(value) {
            this.paginationsObj.currentPage = value;
            this.getTableColumn();
        },
        // 点击切换每页数量事件监听
        handleSizeChange(value) {
            this.paginationsObj.pageSize = value;
            this.getTableColumn();
        },
        // 初始化获取表头数据
        getTableColumn() {
            // 获取开始年和结束年
            let startYear, endYear, years;
            if (this.formSearch.date && this.formSearch.date.length > 0) {
                startYear = new Date(this.formSearch.date[0]).getFullYear();
                endYear = new Date(this.formSearch.date[1]).getFullYear();
                years = endYear - startYear;
            } else {
                startYear = endYear = new Date().getFullYear();
                years = endYear - startYear;
            }
            // console.log(startYear,endYear,years);
            // 渲染单行表头
            function calculateColumn(targetArr) {
                let arr = [];
                if (years === 0) {
                    arr = targetArr.map((item) => {
                        return {
                            label: startYear + item.label,
                            prop: endYear + item.prop
                        };
                    });
                } else {
                    for (let i = years; i >= 0; i--) {
                        arr = targetArr.map((item) => {
                            return {
                                label: (startYear + i) + item.label,
                                prop: (startYear + i) + item.prop
                            };
                        }).concat(arr);
                    }
                }
                return arr;
            }
            // 渲染多行表头
            function calculateMultiColumn(targetArr) {
                let arr = [];
                if (years === 0) {
                    arr = targetArr.map((item) => {
                        return {
                            year: startYear,
                            data: item.data.map((ite) => {
                                return {
                                    label: ite.label,
                                    prop: startYear + ite.prop,
                                    width: ite.width ? ite.width : ""
                                };
                            })
                        };
                    });
                } else {
                    for (let i = years; i >= 0; i--) {
                        arr = targetArr.map((item) => {
                            return {
                                year: startYear + i,
                                data: item.data.map((ite) => {
                                    return {
                                        label: ite.label,
                                        prop: (startYear + i) + ite.prop,
                                        width: ite.width ? ite.width : ""
                                    };
                                })
                            };
                        }).concat(arr);
                    }
                }
                return arr;
            }
            // P职级调整晋升总表表头配置项
            let promotionColumn = [
                {
                    year: 2022,
                    data: [
                        {
                            label: "绩效积分",
                            prop: "performanceIntegral",
                            width: 80
                        },
                        {
                            label: "资质积分",
                            prop: "certificationIntegral",
                            width: 80
                        },
                        {
                            label: "创新积分",
                            prop: "innovateIntegral",
                            width: 80
                        },
                        {
                            label: "总积分",
                            prop: "aggregateScore",
                            width: 70
                        },
                        {
                            label: "P职级",
                            prop: "prank",
                            width: 60
                        },
                        {
                            label: "基础职级调整",
                            prop: "rankAdjust",
                            width: 110
                        },
                        {
                            label: "调整后基础职级",
                            prop: "adjustBaseRank"
                        },
                        {
                            label: "基础职级调整后积分",
                            prop: "adjustScore"
                        },
                        {
                            label: "调整后P职级",
                            prop: "adjustPRank",
                            width: 110
                        },
                        {
                            label: "（基础职级和P职级）调整后剩余绩效积分",
                            prop: "surplusPerformanceIntegral"
                        }
                    ]
                }
            ];
            promotionColumn = calculateMultiColumn(promotionColumn);
            // 绩效积分表头配置项
            let achievementsColumn = [
                {
                    label: "进入部门日期",
                    prop: "enterDepartmentTime"
                },
                {
                    label: "参加本单位日期",
                    prop: "enterUnitTime"
                }
            ];
            let achievementsArr = [
                {
                    label: "年职级",
                    prop: "prank"
                },
                {
                    label: "年绩效等级",
                    prop: "performanceGrade",
                },
                {
                    label: "年绩效积分",
                    prop: "performanceIntegral",
                }
            ];
            achievementsArr = calculateColumn(achievementsArr);
            achievementsColumn.push(...achievementsArr, {
                label: "备注",
                prop: "remark"
            });
            // 资质积分表头配置项
            let qualificationsColumn = [
                {
                    label: "证书名称",
                    prop: "certificateName"
                },
                {
                    label: "证书有效期",
                    prop: "certificateIndate"
                },
                {
                    label: "年份",
                    prop: "year"
                },
                {
                    label: "资质等级",
                    prop: "certificationGrade"
                },
                {
                    label: "资质积分",
                    prop: "certificationIntegral"
                },
                {
                    label: "备注",
                    prop: "remark"
                }
            ];
            // 创新积分表头配置项
            let innovateColumn = [
                {
                    label: "成果名称",
                    prop: "achievementName"
                },
                {
                    label: "成果类别",
                    prop: "achievementCategory"
                },
                {
                    label: "奖项类别",
                    prop: "awardsRank"
                },
                {
                    label: "积分",
                    prop: "innovateIntegral"
                },
                {
                    label: "备注",
                    prop: "remark"
                }
            ];
            // 贡献积分表头配置项
            let contributionColumn = [
                {
                    label: "工龄",
                    prop: "workingYears"
                },
                {
                    label: "积分",
                    prop: "contributionIntegral"
                },
                {
                    label: "备注",
                    prop: "remark"
                }
            ];
            if (this.activeName === "promotion") {
                Object.assign(this.tableConfig, {
                    tableColumn: promotionColumn
                });
            } else if (this.activeName === "achievements") {
                Object.assign(this.tableConfig, {
                    tableColumn: achievementsColumn
                });
            } else if (this.activeName === "qualifications") {
                Object.assign(this.tableConfig, {
                    tableColumn: qualificationsColumn
                });
            } else if (this.activeName === "innovate") {
                Object.assign(this.tableConfig, {
                    tableColumn: innovateColumn
                });
            } else if (this.activeName === "contribution") {
                Object.assign(this.tableConfig, {
                    tableColumn: contributionColumn
                });
            }
            this.getTableData();
        },
        // 初始化获取表格数据
        async getTableData() {
            // 处理相关筛选条件
            let params = {};
            params.current = this.paginationsObj.currentPage;
            params.size = this.paginationsObj.pageSize;
            Object.keys(this.formSearch).forEach((item) => {
                if (this.formSearch[item]) {
                    params[item] = this.formSearch[item];
                    if (typeof params[item] === "string") {
                        params[item] = params[item].trim();
                    }
                }
            });
            if (params.date && params.date.length > 0) {
                params.startYear = params.date[0];
                params.lastYear = params.date[1];
                Reflect.deleteProperty(params, "date");
            }
            let result;
            let getResult = async (fn, params) => {
                return await fn(params).then((res) => {
                    if (res.code === 200) {
                        // this.$message({
                        //     message:"查询成功",
                        //     type:"success"
                        // });
                        return res;
                    } else {
                        this.$message({
                            message: res.message || "请求错误",
                            type: "error"
                        });
                        return false;
                    }
                }).catch(() => {
                    this.tableConfig.data = [];
                    this.paginationsObj.total = 0;
                    this.paginationsObj.currentPage = 1;
                    this.paginationsObj.pageSize = 12;
                });
            }
            if (this.activeName === "promotion") {
                result = await getResult(getPromotionData, params);
            } else if (this.activeName === "achievements") {
                result = await getResult(getAchievementsData, params);
            } else if (this.activeName === "qualifications") {
                result = await getResult(getQualificationsData, params);
            } else if (this.activeName === "innovate") {
                result = await getResult(getInnovateData, params);
            } else if (this.activeName === "contribution") {
                result = await getResult(getContributionData, params);
            }
            if (["promotion", "achievements"].includes(this.activeName) && !!result) {
                result.result.forEach((item) => {
                    if (item.yearList && item.yearList.length > 0) {
                        item.yearList.forEach((ite) => {
                            Object.keys(ite).forEach((it) => {
                                if (it !== "year") {
                                    item[ite.year + it] = ite[it];
                                }
                            });
                        });
                    }
                });
                this.tableConfig.data = result.result;
                this.paginationsObj.total = result.total;
            } else if (result) {
                this.tableConfig.data = result.result;
                this.paginationsObj.total = result.total;
            }
        }
    },
    mounted() {
        // this.getTableData();
    }
}
</script>
<style lang="scss" scoped>
.qilin-pRank {
    @include setWH(100%, 100%);

    >.qilin-pRank-tab {
        background-color: #fff;
        border-radius: 2px;
        box-shadow: 0px 4px 4px 0px rgba(232, 232, 232, 0.2500);

        >.el-form {
            padding: 0 20px;
        }
    }

    >.qilin-pRank-table {
        margin-top: 16px;
        background-color: #fff;
        padding: 16px 20px;

        >.qilin-pRank-table-btn {
            text-align: right;

            >.el-button {
                border-radius: 2px;

                &:nth-child(1) {
                    background: rgba(86, 206, 163, 0.1400);
                    color: #56CEA3;
                    border: 1px solid #56CEA3;
                }

                &:nth-child(2) {
                    background: rgba(250, 173, 20, 0.1500);
                    border: 1px solid #FAAD14;
                    color: #FAAD14;
                }

                &:nth-child(3) {
                    background: rgba(20, 142, 255, 0.1400);
                    border: 1px solid #148EFF;
                    color: #148EFF;
                }

                &:nth-child(4) {
                    background: rgba(155, 152, 255, 0.1400);
                    border: 1px solid #9b98ff;
                    color: #9b98ff;
                }

                &:nth-child(5) {
                    background: rgba(240, 130, 29, 0.1400);
                    border: 1px solid #F0821D;
                    color: #F0821D;
                }
            }

            >div,
            .el-upload {
                display: none;
            }
        }

        >.el-table {
            margin-top: 16px;
        }
    }
}
</style>
// 打印样式设置
<style media="print">
@page {
    size: auto;
    margin: 3mm;
}

@media print {
    html {
        background-color: #ffffff;
        height: auto;
        margin: 0px;
    }

    body {
        border: solid 1px #ffffff;
        /* margin: 10mm 15mm 10mm 15mm; */
    }

    #table table {
        table-layout: auto !important;
    }

    #table .el-table__header-wrapper .el-table__header {
        width: 100% !important;
        border: solid 1px #f2f2f2;
    }

    #table .el-table__body-wrapper .el-table__body {
        width: 100% !important;
    }

    /* #table table {
    table-layout: fixed !important;
  } */
}
</style>
